//
//  T1ViewController.m
//  Commom
//
//  Created by 山刘 on 2018/11/6.
//  Copyright © 2018年 山刘. All rights reserved.
//

#import "T1ViewController.h"

#if __has_include(<Commom/YYBaseHeader.h>)
#import <Commom/YYBaseHeader.h>
#else
#import "YYBaseHeader.h"
#endif

#import "CommomHeader.h"
@interface T1ViewController ()

@end

@implementation T1ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//        NSString *string = [@"id=123456&type=1&fn=uhomeNativeApi.getUserInfoCb" stringByURLEncode];
//        NSString *url = [NSString stringWithFormat:@"uhomeoc://business.openActDetail?%@",string];
    
//    NSString *string = [@"params={\"isTransparent\":\"0\",\"title\":\"bing,MSDN,SEG\",\"urls\":\"https://cn.bing.com/,https://developer.mozilla.org/zh-CN/,https://segmentfault.com/\",\"selected\":\"1\",\"hasShare\":\"1\",\"fn\":\"1\"}" stringByURLEncode];
    NSString *string = [@"params={\"isTransparent\":\"1\",\"title\":\"bing\",\"urls\":\"\",\"selected\":\"0\",\"hasShare\":\"0\",\"fn\":\"1\"}" stringByURLEncode];
    NSString *url = [NSString stringWithFormat:@"uhomeoc://homeservice.setHeadTitle?%@",string];
    
    
//            NSString *string = [@"params={\"icon\":\"1\",\"title\":\"aaa,bbb,cccc\"}" stringByURLEncode];
//            NSString *url = [NSString stringWithFormat:@"uhomeoc://homeservice.setSharePara?%@",string];
    
//        NSString *string = [@"params={\"para\":[\"userId\",\"accessToken\",\"deviceId\",\"communityId\",\"source\",\"versionCode\"],\"fn\":\"uhomeNativeApi.getUserInfoCb\"}" stringByURLEncode];
//        NSString *url = [NSString stringWithFormat:@"uhomeoc://userInfo.get?%@",string];
    
//        NSString *string = [@"params={\"providerSid\":\"1\",\"serviceSid\":\"aaa,bbb,cccc\",\"type\":\"1\",\"fn\":\"1\"}" stringByURLEncode];
//        NSString *url = [NSString stringWithFormat:@"uhomeoc://homeservice.counseling?%@",string];
    
//        NSString *string = [@"params={\"providerSid\":\"1\",\"serviceSid\":\"aaa,bbb,cccc\",\"type\":\"1\",\"fn\":\"1\"}" stringByURLEncode];
//        NSString *url = [NSString stringWithFormat:@"uhomeoc://homeservice.confirmOrder?%@",string];
    
    //    NSString *string = [@"params={\"page\":\"ADVERTISEMENT\",\"para\":{\"advertisingId\":\"广告id\",\"typeId\":\"跳转类型id\",\"href\":\"跳转路径\",\"title\":\"标题\"}}" stringByURLEncode];
    //    NSString *url = [NSString stringWithFormat:@"uhomeoc://system.jumpToNative?%@",string];
    
    //    NSString *string = [@"params={\"fn\":\"ADVERTISEMENT\",\"para\":{\"number\":\"xxx\",\"editale\":\"xxx\",\"type\":\"2\"}}" stringByURLEncode];
    //    NSString *url = [NSString stringWithFormat:@"uhomeoc://system.camera?%@",string];
    
    //    NSString *string = [@"params={\"fn\":\"fn\",\"para\":{\"serviceType\":\"xxx\",\"uri\":[\"xxx\",\"xxx\"]}}" stringByURLEncode];
    //    NSString *url = [NSString stringWithFormat:@"uhomeoc://system.uploadFiles?%@",string];
    
    
//        NSString *string = [@"params={\"title\":\"xxx\",\"icon\":\"xxx\",\"content\":\"xxx\",\"url\":\"xxx\"}" stringByURLEncode];
//        NSString *url = [NSString stringWithFormat:@"uhomeoc://system.socialShare?%@",string];
    
//            NSString *string = [@"params={\"url\":\"xxx\",\"id\":\"xxx\"}" stringByURLEncode];
//            NSString *url = [NSString stringWithFormat:@"uhomeoc://thirdparty.goPayList?%@",string];
    
//        NSString *string = [@"params={\"fn\":\"xxx\",\"number\":\"xxx\",\"editable\":\"1\"}" stringByURLEncode];
//        NSString *url = [NSString stringWithFormat:@"uhomeoc://thirdparty.takePhoto?%@",string];
    
//        NSString *string = [@"params={\"fn\":\"funcname\",\"title\":\"标题\",\"content\":\"内容\",\"type\":\"1\"}" stringByURLEncode];
//        NSString *url = [NSString stringWithFormat:@"uhomeoc://thirdparty.openDialog?%@",string];
    
//        NSString *string = [@"params={\"1payCode\":\"PENGHUA\",\"cbUrl\":\"xxx\",\"payInfo\":{\"payerId\":\"value\",\"vpayId\":\"value\",\"desc\":\"value\",\"addInfo\":\"value\",\"notifyUrl\":\"value\",\"amount\":\"value\",\"pHCallbackUrl\":\"value\",\"communityId\":\"value\",\"businessType\":\"value\"}}" stringByURLEncode];
//        NSString *url = [NSString stringWithFormat:@"uhomeoc://thirdparty.pay?%@",string];
    
//        url = @"https://developer.mozilla.org/zh-CN/";
//    url = @"https://www.uhomecp.com/h5/homeService/";
//    url = @"http://gamma.uhomecp.com/h5/homeService/?app_platform_code=SEGI&company_platform_code=SEGI";
//        url = [NSString stringWithFormat:@"%@%@", kClientRootURL,@"/h5/bonuses-h5-v2/index.html#/exchangeRecord"];
//        url = [NSString stringWithFormat:@"%@%@",kClientRootURL,@"/h5/bonuses-h5/index.html?router=helpCenter"];
//        url = [NSString stringWithFormat:@"%@%@", kClientRootURL,@"/h5/bonuses-h5-v2/index.html#/"];
//        url = [NSString stringWithFormat:@"%@/%@%@",kClientRootURL,kUhomecp_app,[NSString stringWithFormat:@"/protocol/disclaimer.html?app_platform_code=%@&company_platform_code=%@",kAppPlatformCode,kAppPlatformCode]];
////    url = @"https://www.uhomecp.com/h5/agreement/index.html?app_platform_code=SEGI&company_platform_code=SEGI";
//    url = @"https://www.uhomecp.com/h5/community-survey-h5/#/surveyList?isHideHeader=1";
//        url = [NSString stringWithFormat:@"%@%@", kClientRootURL,@"/h5/bonuses-h5/index.html?router=lvcondition"];
//        url = [self segWebActivity];
//        url = @"http://gamma.uhomecp.com/h5/transaction-sys-h5/#/Uhome/UhomeHonmePage?app_platform_code=SEGI&isHideHeader=1";
//    url = @"http://gamma.uhomecp.com/h5/transaction-sys-h5/#/Uhome/UhomeHonmePage?&app_platform_code=SYWY&company_platform_code=SYWY";
    url = @"http://gamma.uhomecp.com/h5/community-survey-h5/#/surveyList?app_platform_code=SYWY&company_platform_code=SYWY";
//    UIViewController *vc = [[SEGUhomeMediator sharedInstance] seg_initWebViewLoadControllerV2:@{@"linkURL":url}];
//    [self.navigationController pushViewController:vc animated:YES];
    
//    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:@"https://www.uhomecp.com/user-service/rest-api/v1/ocm/getCommunityBizConfig" parameters:@{@"communityId":@"1007380"} completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
//    }];
}


-(NSString*)segWebVisitorManagement{
    
    NSString *secretId = @"EmnORxY9w5MziPyMxLDxq9G0WhxycPl97uCjdiyhiF5N21UX7p";
    NSString *secretKey = @"ksQOE2KW56ZH9wOECHdl";
    
    NSString *orgId = [SEGProfileManager sharedManager].profile.jobCommunity;
    NSString *mobile = [SEGProfileManager sharedManager].profile.tel;
    NSString *userName = [[SEGProfileManager sharedManager].profile.nickname stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *timeStamp = [NSString stringWithFormat:@"%zd",[[NSDate date] timeIntervalSince1970] * 1000];
    NSString *srcStr = [NSString stringWithFormat:@"mobile=%@&orgId=%@&secretId=%@&timeStamp=%@&userName=%@",
                        mobile,orgId,secretId,timeStamp,[SEGProfileManager sharedManager].profile.nickname];
    NSString *signature =  [srcStr hmacSHA1StringWithKey:secretKey];// [ImageEnarge seg_Hmacsha1:srcStr key:secretKey];
    NSString *signature_URLEncod = [signature stringByURLEncode];
    
    return [NSString stringWithFormat:@"https://visitor.zhimahezi.net/julin/?mobile=%@&orgId=%@&secretId=%@&timeStamp=%@&userName=%@&signature=%@&end=0",
            mobile,orgId,secretId,timeStamp,userName,signature_URLEncod];
}

-(NSString *)segWebDigitalCommunity{
    return [NSString stringWithFormat:@"%@%@#/digitalCommunity?communityId=%@&badge=%@&user_type=%@",
            kClientRootURL,
            @"/h5/home-page-remould/index.html",
            [SEGProfileManager sharedManager].profile.jobCommunity,
            [[SEGProfileManager sharedManager].profile.type isEqualToString:@"5"] ? ([[SEGProfileManager sharedManager].profile.submitAuthFlag isEqualToString:@"1"] ? @"0" : @"1") : @"0",
            [SEGProfileManager sharedManager].profile.type];
}

-(NSString *)segWebCMHK_YIKATOG{
    NSInteger intervalTime = (NSInteger)[[NSDate date] timeIntervalSince1970] * 1000;
    NSString *timeStr = [NSString stringWithFormat:@"%zd",intervalTime];
    
    //秘钥 -- 客户端秘钥，App接口专用
    NSString *AppSecret = @"OLPWDDFAMAMRUAEXHIZEBVXGOPOQEZ";
    //测试用数据 uid=87&cid=2394311
    //NSString *data = [NSString stringWithFormat:@"K=1000200001&uid=87&cid=2394311&cmid=%@&time=%@",kAccountCommunityID,timeStr];
    //正式数据
    NSString *data = [NSString stringWithFormat:@"K=1000200001&uid=%@&cid=%@&cmid=%@&time=%@&phone=%@&name=%@&idno=%@",[SEGProfileManager sharedManager].profile.userId,[SEGProfileManager sharedManager].profile.custId,[SEGProfileManager sharedManager].profile.jobCommunity,timeStr,[SEGProfileManager sharedManager].profile.tel,@"",@""];
    
    //签名
    NSString *MD5STRING = [NSString stringWithFormat:@"%@|%@",data,AppSecret];
    NSString *signStr =  [[MD5STRING md5String] uppercaseString];//  [SEGUtils md5:MD5STRING].uppercaseString;
    
    NSString *loadUrl = [NSString stringWithFormat:@"http://appsrv.cmpmc.com:1005/h5/app/AppUser/Auth/MyCard?%@&sign=%@",data,signStr];
    return loadUrl;
}

-(NSString*)segWebActivity{
    NSString* roodom = [[NSDate date] stringWithFormat:@"yyyyMMdd"];
    NSString* roodom1 = [[NSDate date] stringWithFormat:@"HHmmss"];
    return [NSString stringWithFormat:@"%@/lottery/lotteryForIOS.html?userId=%@&_rand=%@%@",
            kClientRootURL,
            [SEGProfileManager sharedManager].profile.userId,
            roodom,
            roodom1];
}
@end
